package com.chy.utilsdemo.UriUtil;

import lombok.extern.slf4j.Slf4j;

import java.net.URI;
import java.net.URISyntaxException;

/**
 * 功能： http地址验证工具类
 *
 * @author CHY
 */
@Slf4j
public class UriUtil {
    public static boolean isRightUri(String uri) {
        final URI sourceUri = URI.create(uri);
        try {
            new URI(sourceUri.getScheme(), null, sourceUri.getHost(), sourceUri.getPort(), sourceUri.getPath(), sourceUri.getQuery(), sourceUri.getFragment());
        } catch (URISyntaxException e) {
            log.error(String.format("uri地址[%s]验证错误", uri), e);
            return false;
        }
        return true;
    }
}
